home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Sound / SPlayer / ARexxWebServer / webserver.rexx < prev   
OS/2 REXX Batch file  |  1998-06-29  |  2KB  |  84 lines

  1. /*
  2.    ARexx Web Server
  3.    Version 2.0
  4. */
  5.  
  6. if ~show('L','rexxsupport.library') then addlib('rexxsupport.library',0,-30,0)
  7.  
  8. path="amitcp:www"   /* No trailing "/"!! */
  9. pull a
  10. file=subword(a,2,1)
  11. if right(file,1)="/" then file=file"index.html"
  12. if index(upper(file),".CGI")~=0 then signal cgi
  13. if exists(path||file)=0 then bad=1
  14. if index(file,"//")~=0 then signal error
  15. if index(file,":")~=0 then signal error
  16. ext=upper(substr(file,lastpos(".",file),length(file)))
  17. mime="text/html"
  18. if ext=".HTML"|ext=".HTM"|ext=".HML" then mime="text/html"
  19. if ext=".DOC"|ext=".TXT" then mime="text/plain"
  20. if ext=".GUIDE" then mime="text/aguide"
  21. if ext=".GIF" then mime="image/gif"
  22. if ext=".JPG"|ext=".JPEG" then mime="image/jpeg"
  23. if ext=".WAV"|ext=".AU"|ext=".8SVX" then mime="audio/*"
  24. if ext=".MID"|ext=".MIDI" then mime="audio/x-midi"
  25. if ext=".LHA"|ext=".LZH"|ext=".LZX" then mime="application/octet-stream"
  26. if ext=".MOCHA" then mime="language/mocha"
  27. if ext=".GSM"|ext=".GSD" then mime="audio/x-gsm"
  28. if ext=".PS" then mime="application/postscript"
  29. say "HTTP/1.0 200 OK"
  30. say "Server: ARexxWebServer/2.0"
  31. say "Date: "||date()||" "||time()
  32. say "Author: Casey Halverson (cmdo@gte.net)"
  33. say "Accept-ranges: bytes"
  34. say "Content-length: "||subword(statef(path||file),2,1)
  35. say "Content-type: "||mime
  36. if bad=1 then signal bad
  37. say ""
  38. if mime~="text/html" then signal binary
  39. call open(1,path||file,'r')
  40. do until eof(1)=1
  41. a=readln(1)
  42. if index(a,"<! CGI=")~=0 then call cgi_html
  43. say a
  44. end
  45. exit
  46.  
  47. cgi:
  48. cgi=substr(file,lastpos("/",file)+1)
  49. cgi=translate(cgi," ","?")
  50. if exists(path||"/cgi-bin/"||subword(cgi,1,1))=0 then signal bad
  51. say "HTTP/1.0 200 OK"
  52. say "Server: ARexxWebServer/2.0"
  53. say "Author: Casey Halverson (cmdo@gte.net)"
  54. say "Date: "||date()||" "||time()
  55. say ""
  56. address command "rx "||path||"/cgi-bin/"||cgi||" "||file
  57. exit
  58.  
  59. cgi_html:
  60. parse var a null'<! CGI="'rexx'">'stuff
  61. say null
  62. address command "rx "||path||"/cgi-bin/"||rexx
  63. say stuff
  64. a=""
  65. return
  66.  
  67. binary:
  68. address command 'c:copy "'||path||file||'" CONSOLE:'
  69. exit
  70.  
  71. bad:
  72. say "HTTP/1.0 404 Not Found"
  73. say "Content-Type: text/html"
  74. say ""
  75. say "<HTML><STRONG><H1>ERROR</H1></STRONG><H4><P><P>ARexxWebServer error 404:<BR> Page does not exist<BR>FILENAME: "||file||"</HTML>"
  76. exit
  77.  
  78. error:
  79. say "HTTP/1.0 400 Forbidden"
  80. say "Content-Type: text/html"
  81. say ""
  82. say "<STRONG><H1>ERROR</H1></STRONG><H4><P><P>ARexxWebServer error 400:<BR> You may not place : or double //'s in a URL<BR>FILENAME: "||file||"</HTML>"
  83. exit
  84.